package com.group4.admin.beans;

import com.group4.entity.Teacher;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.event.ActionEvent;

/**
 * Controlles the adminTeacher.xhtml
 * 
 * @author Andreas, anjonas
 */
@ManagedBean
@RequestScoped
public class AdminTeacherControllerBean {
    
    @ManagedProperty(value="#{adminTeacherModelBean}")
    AdminTeacherModelBean amb;

    /** Creates a new instance of AdminTeacherControllerBean */
    public AdminTeacherControllerBean() {
    }

    public AdminTeacherModelBean getAmb() {
        return amb;
    }

    public void setAmb(AdminTeacherModelBean amb) {
        this.amb = amb;
    }
    
    // listens after delete event
    public void delete(ActionEvent e) {
        amb.deleteTeacher((Teacher)e.getComponent().getAttributes().get("teacher"));
    }
    
    // listens after edit or add new event
    public void change(ActionEvent e) {
        System.out.println("id: " + amb.getEditId());
        if (!amb.getEditId().isEmpty())
            amb.editTeacher();
        else
            amb.addNewTeacher();
    }
    
}
